<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>want显式隐式规则 | East'blog</title><meta name="author" content="侯玉东"><meta name="copyright" content="侯玉东"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="want显式隐式规则">
<meta property="og:type" content="article">
<meta property="og:title" content="want显式隐式规则">
<meta property="og:url" content="https://houyudong1989.gitee.io/blog/2023/11/29/harmonyOS/want%E6%98%BE%E5%BC%8F%E9%9A%90%E5%BC%8F%E8%A7%84%E5%88%99/index.html">
<meta property="og:site_name" content="East&#39;blog">
<meta property="og:description" content="want显式隐式规则">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://houyudong1989.gitee.io/blog/img/library1.jpeg">
<meta property="article:published_time" content="2023-11-28T16:00:00.000Z">
<meta property="article:modified_time" content="2023-11-28T10:19:22.109Z">
<meta property="article:author" content="侯玉东">
<meta property="article:tag" content="harmonyOS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://houyudong1989.gitee.io/blog/img/library1.jpeg"><link rel="shortcut icon" href="/blog/img/head.jpg"><link rel="canonical" href="https://houyudong1989.gitee.io/blog/2023/11/29/harmonyOS/want%E6%98%BE%E5%BC%8F%E9%9A%90%E5%BC%8F%E8%A7%84%E5%88%99/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'want显式隐式规则',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-11-28 18:19:22'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (true) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/blog/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">70</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友联</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('/blog/img/library2.jpeg')"><nav id="nav"><span id="blog-info"><a href="/blog/" title="East'blog"><img class="site-icon" src="/blog/img/head.jpg"/><span class="site-name">East'blog</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友联</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">want显式隐式规则</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-11-28T16:00:00.000Z" title="发表于 2023-11-29 00:00:00">2023-11-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-11-28T10:19:22.109Z" title="更新于 2023-11-28 18:19:22">2023-11-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/harmonyOS/">harmonyOS</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="want显式隐式规则"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">want是对象间信息传递的载体，可以用于应用组件间的信息传递。其使用场景之一是作为startAbility()的参数，包含了指定的启动目标以及启动时需携带的相关数据，如bundleName和abilityName字段分别指明目标Ability所在应用的包名以及对应包内的Ability名称。当UIAbilityA启动UIAbilityB并需要传入一些数据给UIAbilityB时，Want可以作为一个载体将数据传给UIAbilityB。</span><br></pre></td></tr></table></figure>

<p><img src="1701164939374.png" alt="1701164939374"></p>
<h1 id="want-类型"><a href="#want-类型" class="headerlink" title="want 类型"></a>want 类型</h1><h2 id="显式want"><a href="#显式want" class="headerlink" title="显式want"></a>显式want</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">在启动Ability时指定了abilityName和bundleName的Want称为显式Want。</span><br><span class="line"></span><br><span class="line">当有明确处理请求的对象时，通过提供目标Ability所在应用的包名信息（bundleName），并在Want内指定abilityName便可启动目标Ability。显式Want通常用于在当前应用开发中启动某个已知的Ability。</span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> wantInfo = &#123;</span><br><span class="line">    <span class="attr">deviceId</span>: <span class="string">&#x27;&#x27;</span>, <span class="comment">// deviceId为空表示本设备</span></span><br><span class="line">    <span class="attr">bundleName</span>: <span class="string">&#x27;com.example.myapplication&#x27;</span>,</span><br><span class="line">    <span class="attr">abilityName</span>: <span class="string">&#x27;FuncAbility&#x27;</span>,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p><strong>显式Want匹配原理</strong></p>
</blockquote>
<table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">类型</th>
<th align="left">匹配项</th>
<th align="left">必选</th>
<th align="left">规则</th>
</tr>
</thead>
<tbody><tr>
<td align="left">deviceId</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">留空将仅匹配本设备内Ability。</td>
</tr>
<tr>
<td align="left">bundleName</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">是</td>
<td align="left">如果指定abilityName，而不指定bundleName，则匹配失败。</td>
</tr>
<tr>
<td align="left">moduleName</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">留空时当同一个应用内存在多个模块且模块间存在重名Ability，将默认匹配第一个。</td>
</tr>
<tr>
<td align="left">abilityName</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">是</td>
<td align="left">该字段必须设置表示显式匹配。</td>
</tr>
<tr>
<td align="left">uri</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">系统匹配时将忽略该参数，但仍可作为参数传递给目标Ability。</td>
</tr>
<tr>
<td align="left">type</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">系统匹配时将忽略该参数，但仍可作为参数传递给目标Ability。</td>
</tr>
<tr>
<td align="left">action</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">系统匹配时将忽略该参数，但仍可作为参数传递给目标Ability。</td>
</tr>
<tr>
<td align="left">entities</td>
<td align="left">Array <code>&lt;string&gt;</code></td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">系统匹配时将忽略该参数，但仍可作为参数传递给目标Ability。</td>
</tr>
<tr>
<td align="left">flags</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">不参与匹配，直接传递给系统处理，一般用来设置运行态信息，例如URI数据授权等。</td>
</tr>
<tr>
<td align="left">parameters</td>
<td align="left">{[key: string]: any}</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">不参与匹配，应用自定义数据将直接传递给目标Ability。</td>
</tr>
</tbody></table>
<h2 id="隐式want"><a href="#隐式want" class="headerlink" title="隐式want"></a>隐式want</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">在启动UIAbility时未指定abilityName的Want称为隐式Want。</span><br><span class="line"></span><br><span class="line">当请求处理的对象不明确时，希望在当前应用中使用其他应用提供的某个能力（通过skills标签定义），而不关心提供该能力的具体应用，可以使用隐式Want。例如使用隐式Want描述需要打开一个链接的请求，而不关心通过具体哪个应用打开，系统将匹配声明支持该请求的所有应用。</span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> wantInfo = &#123;</span><br><span class="line">    <span class="attr">action</span>: <span class="string">&#x27;ohos.want.action.search&#x27;</span>,</span><br><span class="line">    <span class="comment">// entities can be omitted</span></span><br><span class="line">    <span class="attr">entities</span>: [ <span class="string">&#x27;entity.system.browsable&#x27;</span> ],</span><br><span class="line">    <span class="attr">uri</span>: <span class="string">&#x27;https://www.test.com:8080/query/student&#x27;</span>,</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&#x27;text/plain&#x27;</span>,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<blockquote>
<p><strong>隐式Want匹配原理</strong></p>
</blockquote>
<table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">类型</th>
<th align="left">匹配项</th>
<th align="left">必选</th>
<th align="left">规则</th>
</tr>
</thead>
<tbody><tr>
<td align="left">deviceId</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">跨设备目前不支持隐式调用。说明当前版本暂不支持跨设备能力。</td>
</tr>
<tr>
<td align="left">abilityName</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">该字段必须留空表示隐式匹配。</td>
</tr>
<tr>
<td align="left">bundleName</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">- 声明bundleName时，隐式搜索将仅限于对应应用包内。- 声明bundleName与moduleName时，隐式搜索将仅限于对应应用的对应Module内。- 单独声明moduleName时，该字段无效。- 同时声明bundleName与moduleName时，隐式搜索将仅限于对应应用包内的对应模块内。这些字段将用来隐式匹配，具体规则可参考<a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/explicit-implicit-want-mappings-0000001478061453-V3#ZH-CN_TOPIC_0000001523808814__%E9%9A%90%E5%BC%8Fwant%E5%8C%B9%E9%85%8D%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3">隐式Want匹配原理详解</a>。</td>
</tr>
<tr>
<td align="left">moduleName</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">-</td>
</tr>
<tr>
<td align="left">uri</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">-</td>
</tr>
<tr>
<td align="left">type</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">-</td>
</tr>
<tr>
<td align="left">action</td>
<td align="left">string</td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">-</td>
</tr>
<tr>
<td align="left">entities</td>
<td align="left">Array <code>&lt;string&gt;</code></td>
<td align="left">是</td>
<td align="left">否</td>
<td align="left">-</td>
</tr>
<tr>
<td align="left">flags</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">不参与匹配，直接传递给系统处理，一般用来设置运行态信息，例如URI数据授权等。</td>
</tr>
<tr>
<td align="left">parameters</td>
<td align="left">{[key: string]: any}</td>
<td align="left">否</td>
<td align="left">否</td>
<td align="left">不参与匹配，应用自定义数据将直接传递给目标Ability。</td>
</tr>
</tbody></table>
<h3 id="隐式Want匹配原理详解"><a href="#隐式Want匹配原理详解" class="headerlink" title="隐式Want匹配原理详解"></a>隐式Want匹配原理详解</h3><blockquote>
<p>从隐式Want的定义，可得知：</p>
<ul>
<li>调用方传入的want参数，表明调用方需要执行的操作，并提供相关数据以及其他应用类型限制。</li>
<li>待匹配Ability的skills配置，声明其具备的能力（module.json5配置文件中的skills标签 参数）。</li>
</ul>
<p>系统将调用方传入的want参数（包含action、entities、uri和type属性）与已安装待匹配的应用Ability的skills配置（包含actions、entities、uris和type属性）依次进行匹配。当四个属性匹配均通过，则此应用才会被应用选择器展示给用户进行选择。</p>
</blockquote>
<h3 id="want参数的action匹配规则"><a href="#want参数的action匹配规则" class="headerlink" title="want参数的action匹配规则"></a>want参数的action匹配规则</h3><blockquote>
<p>将调用方传入的want参数的action与待匹配Ability的skills配置中的actions进行匹配。</p>
<ul>
<li>调用方传入的want参数的action为空，待匹配Ability的skills配置中的actions为空，则action匹配失败。</li>
<li>调用方传入的want参数的action不为空，待匹配Ability的skills配置中的actions为空，则action匹配失败。</li>
<li>调用方传入的want参数的action为空，待匹配Ability的skills配置中的actions不为空，则action匹配成功。</li>
<li>调用方传入的want参数的action不为空，待匹配Ability的skills配置中的actions不为空且包含调用方传入的want参数的action，则action匹配成功。</li>
<li>调用方传入的want参数的action不为空，待匹配Ability的skills配置中的actions不为空且不包含调用方传入的want参数的action，则action匹配失败。</li>
</ul>
</blockquote>
<h3 id="want参数的entities匹配规则"><a href="#want参数的entities匹配规则" class="headerlink" title="want参数的entities匹配规则"></a>want参数的entities匹配规则</h3><blockquote>
<p>将调用方传入的want参数的entities与待匹配Ability的skills配置中的entities进行匹配。</p>
<ul>
<li>调用方传入的want参数的entities为空，待匹配Ability的skills配置中的entities不为空，则entities匹配成功。</li>
<li>调用方传入的want参数的entities为空，待匹配Ability的skills配置中的entities为空，则entities匹配成功。</li>
<li>调用方传入的want参数的entities不为空，待匹配Ability的skills配置中的entities为空，则entities匹配失败。</li>
<li>调用方传入的want参数的entities不为空，待匹配Ability的skills配置中的entities不为空且包含调用方传入的want参数的entities，则entities匹配成功。</li>
<li>调用方传入的want参数的entities不为空，待匹配Ability的skills配置中的entities不为空且不完全包含调用方传入的want参数的entities，则entities匹配失败。</li>
</ul>
</blockquote>
<p><img src="1701166231864.png" alt="1701166231864"></p>
<h3 id="want参数的uri和type匹配规则"><a href="#want参数的uri和type匹配规则" class="headerlink" title="want参数的uri和type匹配规则"></a>want参数的uri和type匹配规则</h3><blockquote>
<p>调用方传入的want参数中设置uri和type参数发起组件启动请求，系统会遍历当前系统已安装的组件列表，并逐个匹配待匹配Ability的skills配置中的uris数组，如果待匹配Ability的skills配置中的uris数组中只要有一个可以匹配调用方传入的want参数中设置的uri和type即为匹配成功。</p>
</blockquote>
<p><img src="1701166303132.png" alt="1701166303132"></p>
<h2 id="Want参数说明"><a href="#Want参数说明" class="headerlink" title="Want参数说明"></a>Want参数说明</h2><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">读写属性</th>
<th align="left">类型</th>
<th align="left">必填</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">deviceId</td>
<td align="left">只读</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">表示目标Ability所在设备ID。如果未设置该字段，则表明本设备。</td>
</tr>
<tr>
<td align="left">bundleName</td>
<td align="left">只读</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">表示目标Ability所在应用名称。</td>
</tr>
<tr>
<td align="left">moduleName</td>
<td align="left">只读</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">表示目标Ability所属的模块名称。</td>
</tr>
<tr>
<td align="left">abilityName</td>
<td align="left">只读</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">表示目标Ability名称。如果未设置该字段，则该Want为隐式。如果在Want中同时指定了bundleName，moduleName和abilityName，则Want可以直接匹配到指定的Ability。</td>
</tr>
<tr>
<td align="left">uri</td>
<td align="left">只读</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">表示携带的数据，一般配合type使用，指明待处理的数据类型。如果在Want中指定了uri，则Want将匹配指定的Uri信息，包括scheme, schemeSpecificPart, authority和path信息。</td>
</tr>
<tr>
<td align="left">type</td>
<td align="left">只读</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">表示携带数据类型，使用MIME类型规范。例如：”text&#x2F;plain”、”image&#x2F;*”等。</td>
</tr>
<tr>
<td align="left"><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-ability-wantconstant-0000001544583997-V3">action</a></td>
<td align="left">只读</td>
<td align="left">string</td>
<td align="left">否</td>
<td align="left">表示要执行的通用操作（如：查看、分享、应用详情）。在隐式Want中，您可定义该字段，配合uri或parameters来表示对数据要执行的操作。如打开，查看该uri数据。例如，当uri为一段网址，action为ohos.want.action.viewData则表示匹配可查看该网址的Ability。</td>
</tr>
<tr>
<td align="left"><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-ability-wantconstant-0000001544583997-V3">entities</a></td>
<td align="left">只读</td>
<td align="left">Array <code>&lt;string&gt;</code></td>
<td align="left">否</td>
<td align="left">表示目标Ability额外的类别信息（如：浏览器，视频播放器），在隐式Want中是对action的补充。在隐式Want中，您可定义该字段，来过滤匹配UIAbility类别，如必须是浏览器。例如，在action字段的举例中，可存在多个应用声明了支持查看网址的操作，其中有应用为普通社交应用，有的为浏览器应用，您可通过entity.system.browsable过滤掉非浏览器的其他应用。</td>
</tr>
<tr>
<td align="left"><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-ability-wantconstant-0000001544583997-V3#ZH-CN_TOPIC_0000001574088649__wantconstantflags">flags</a></td>
<td align="left">只读</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">表示处理Want的方式。例如通过wantConstant.Flags.FLAG_ABILITY_CONTINUATION表示是否以设备间迁移方式启动Ability。</td>
</tr>
<tr>
<td align="left">parameters</td>
<td align="left">只读</td>
<td align="left">{[key: string]: any}</td>
<td align="left">否</td>
<td align="left">此参数用于传递自定义数据，通过用户自定义的键值对进行数据填充，具体支持的数据类型如<a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-app-ability-want-0000001493584192-V3">Want API</a>所示。</td>
</tr>
</tbody></table>
<blockquote>
<p>说明</p>
<p>根据系统中待匹配Ability的匹配情况不同，使用隐式Want启动Ability时会出现以下三种情况。</p>
<ul>
<li>未匹配到满足条件的Ability：启动失败。</li>
<li>匹配到一个满足条件的Ability：直接启动该Ability。</li>
<li>匹配到多个满足条件的Ability（UIAbility）：弹出选择框让用户选择。</li>
</ul>
</blockquote>
<h1 id="常见action与entities"><a href="#常见action与entities" class="headerlink" title="常见action与entities"></a>常见action与entities</h1><h2 id="action"><a href="#action" class="headerlink" title="action"></a><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-ability-wantconstant-0000001544583997-V3#ZH-CN_TOPIC_0000001574088649__wantconstantaction">action</a></h2><p>表示调用方要执行的通用操作（如查看、分享、应用详情）。在隐式Want中，您可定义该字段，配合uri或parameters来表示对数据要执行的操作。如打开，查看该uri数据。例如，当uri为一段网址，action为ohos.want.action.viewData则表示匹配可查看该网址的Ability。在Want内声明action字段表示希望被调用方应用支持声明的操作。在被调用方应用配置文件skills字段内声明actions表示该应用支持声明操作。</p>
<p><strong>常见action</strong></p>
<ul>
<li>ACTION_HOME：启动应用入口组件的动作，需要和ENTITY_HOME配合使用；系统桌面应用图标就是显式的入口组件，点击也是启动入口组件；入口组件可以配置多个。</li>
<li>ACTION_CHOOSE：选择本地资源数据，例如联系人、相册等；系统一般对不同类型的数据有对应的Picker应用，例如联系人和图库。</li>
<li>ACTION_VIEW_DATA：查看数据，当使用网址uri时，则表示显示该网址对应的内容。</li>
<li>ACTION_VIEW_MULTIPLE_DATA：发送多个数据记录的操作。</li>
</ul>
<h2 id="entities"><a href="#entities" class="headerlink" title="entities"></a><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-ability-wantconstant-0000001544583997-V3#ZH-CN_TOPIC_0000001574088649__wantconstantentity">entities</a></h2><p>表示目标Ability的类别信息（如浏览器、视频播放器），在隐式Want中是对action的补充。在隐式Want中，开发者可定义该字段，来过滤匹配应用的类别，例如必须是浏览器。在Want内声明entities字段表示希望被调用方应用属于声明的类别。在被调用方应用配置文件skills字段内声明entites表示该应用支持的类别。</p>
<p><strong>常用entities</strong></p>
<ul>
<li>ENTITY_DEFAULT：默认类别无实际意义。</li>
<li>ENTITY_HOME：主屏幕有图标点击入口类别。</li>
<li>ENTITY_BROWSABLE：指示浏览器类别。</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-ability-wantconstant-0000001544583997-V3">want常量说明</a></p>
<h1 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h1><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 打开应用设置页面 </span></span><br><span class="line"> <span class="keyword">let</span> wantInfo = &#123;</span><br><span class="line">    <span class="attr">action</span>: <span class="string">&#x27;android.settings.APPLICATION_DETAILS_SETTINGS&#x27;</span>,</span><br><span class="line">    <span class="attr">uri</span>:<span class="string">`package:com.test.myapplication`</span></span><br><span class="line">  &#125;</span><br><span class="line">  context.<span class="title function_">startAbilityForResult</span>(wantInfo)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 打开系统图库页面 </span></span><br><span class="line">  <span class="keyword">let</span> wantInfo = &#123;</span><br><span class="line">    <span class="string">&quot;type&quot;</span>: <span class="string">&quot;image/*&quot;</span>,</span><br><span class="line">    <span class="string">&quot;action&quot;</span>: <span class="string">&quot;android.intent.action.GET_CONTENT&quot;</span></span><br><span class="line">  &#125;</span><br><span class="line">  context.<span class="title function_">startAbilityForResult</span>(wantInfo)</span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://houyudong1989.gitee.io/blog">侯玉东</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://houyudong1989.gitee.io/blog/2023/11/29/harmonyOS/want%E6%98%BE%E5%BC%8F%E9%9A%90%E5%BC%8F%E8%A7%84%E5%88%99/">https://houyudong1989.gitee.io/blog/2023/11/29/harmonyOS/want%E6%98%BE%E5%BC%8F%E9%9A%90%E5%BC%8F%E8%A7%84%E5%88%99/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://houyudong1989.gitee.io/blog" target="_blank">East'blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/harmonyOS/">harmonyOS</a></div><div class="post_share"><div class="social-share" data-image="/blog/img/library1.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2023/12/02/harmonyOS/Canvas%E7%BB%98%E5%88%B6%E6%9F%B1%E7%8A%B6%E5%9B%BE/" title="canvas绘制柱状图"><img class="cover" src="/blog/img/library1.jpeg" onerror="onerror=null;src='/blog/img/friend_404.gif'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">canvas绘制柱状图</div></div></a></div><div class="next-post pull-right"><a href="/blog/2023/11/28/harmonyOS/%E6%95%B0%E6%8D%AE%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86/" title="数据状态管理"><img class="cover" src="/blog/img/library1.jpeg" onerror="onerror=null;src='/blog/img/friend_404.gif'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">数据状态管理</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2024/01/20/harmonyOS/ArkUI-X/" title="ArkUI-X"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-01-20</div><div class="title">ArkUI-X</div></div></a></div><div><a href="/blog/2023/12/15/harmonyOS/Canvas%E7%BB%98%E5%88%B6%E6%8A%98%E7%BA%BF%E5%9B%BE/" title="canvas绘制折线图"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-15</div><div class="title">canvas绘制折线图</div></div></a></div><div><a href="/blog/2023/12/02/harmonyOS/Canvas%E7%BB%98%E5%88%B6%E6%9F%B1%E7%8A%B6%E5%9B%BE/" title="canvas绘制柱状图"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-02</div><div class="title">canvas绘制柱状图</div></div></a></div><div><a href="/blog/2024/03/25/harmonyOS/commonevent%E3%80%81eventhub%E3%80%81emitter%E5%92%8Cworker%E4%BD%BF%E7%94%A8/" title="commonevent、eventhub、emitter和worker使用"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-03-25</div><div class="title">commonevent、eventhub、emitter和worker使用</div></div></a></div><div><a href="/blog/2023/11/05/harmonyOS/hdc/" title="hdc 使用帮助"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-11-05</div><div class="title">hdc 使用帮助</div></div></a></div><div><a href="/blog/2023/12/26/harmonyOS/router%E8%B7%AF%E7%94%B1/" title="router路由跳转"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-26</div><div class="title">router路由跳转</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/blog/img/head.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">侯玉东</div><div class="author-info__description">生命不息，奋斗不止</div></div><div class="card-info-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">70</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/houyudong1989"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/houyudong1989" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:420098321@qq.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎来到我的博客！！！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A6%82%E8%BF%B0"><span class="toc-number">1.</span> <span class="toc-text">概述</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#want-%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.</span> <span class="toc-text">want 类型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%98%BE%E5%BC%8Fwant"><span class="toc-number">2.1.</span> <span class="toc-text">显式want</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9A%90%E5%BC%8Fwant"><span class="toc-number">2.2.</span> <span class="toc-text">隐式want</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9A%90%E5%BC%8FWant%E5%8C%B9%E9%85%8D%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3"><span class="toc-number">2.2.1.</span> <span class="toc-text">隐式Want匹配原理详解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#want%E5%8F%82%E6%95%B0%E7%9A%84action%E5%8C%B9%E9%85%8D%E8%A7%84%E5%88%99"><span class="toc-number">2.2.2.</span> <span class="toc-text">want参数的action匹配规则</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#want%E5%8F%82%E6%95%B0%E7%9A%84entities%E5%8C%B9%E9%85%8D%E8%A7%84%E5%88%99"><span class="toc-number">2.2.3.</span> <span class="toc-text">want参数的entities匹配规则</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#want%E5%8F%82%E6%95%B0%E7%9A%84uri%E5%92%8Ctype%E5%8C%B9%E9%85%8D%E8%A7%84%E5%88%99"><span class="toc-number">2.2.4.</span> <span class="toc-text">want参数的uri和type匹配规则</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Want%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E"><span class="toc-number">2.3.</span> <span class="toc-text">Want参数说明</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B8%B8%E8%A7%81action%E4%B8%8Eentities"><span class="toc-number">3.</span> <span class="toc-text">常见action与entities</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#action"><span class="toc-number">3.1.</span> <span class="toc-text">action</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#entities"><span class="toc-number">3.2.</span> <span class="toc-text">entities</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B"><span class="toc-number">4.</span> <span class="toc-text">示例</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/06/c++/5%E3%80%81%E5%AD%97%E7%AC%A6%E5%92%8C%E5%AD%97%E7%AC%A6%E4%B8%B2/" title="字符和字符串"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="字符和字符串"/></a><div class="content"><a class="title" href="/blog/2024/05/06/c++/5%E3%80%81%E5%AD%97%E7%AC%A6%E5%92%8C%E5%AD%97%E7%AC%A6%E4%B8%B2/" title="字符和字符串">字符和字符串</a><time datetime="2024-05-06T11:15:27.280Z" title="发表于 2024-05-06 19:15:27">2024-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/06/c++/4%E3%80%81%E6%8C%87%E9%92%88%E5%92%8C%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88/" title="指针和函数指针"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="指针和函数指针"/></a><div class="content"><a class="title" href="/blog/2024/05/06/c++/4%E3%80%81%E6%8C%87%E9%92%88%E5%92%8C%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88/" title="指针和函数指针">指针和函数指针</a><time datetime="2024-05-06T11:14:29.047Z" title="发表于 2024-05-06 19:14:29">2024-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/05/python/7%E3%80%81m3u8%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F/" title="m3u8格式"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="m3u8格式"/></a><div class="content"><a class="title" href="/blog/2024/05/05/python/7%E3%80%81m3u8%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F/" title="m3u8格式">m3u8格式</a><time datetime="2024-05-05T01:43:26.865Z" title="发表于 2024-05-05 09:43:26">2024-05-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/04/30/android/charles%E5%AE%89%E5%8D%93%E6%89%8B%E6%9C%BA%E6%8A%93%E5%8C%85/" title="charles 抓包"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="charles 抓包"/></a><div class="content"><a class="title" href="/blog/2024/04/30/android/charles%E5%AE%89%E5%8D%93%E6%89%8B%E6%9C%BA%E6%8A%93%E5%8C%85/" title="charles 抓包">charles 抓包</a><time datetime="2024-04-30T06:49:29.279Z" title="发表于 2024-04-30 14:49:29">2024-04-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/04/26/python/13%E3%80%81playwright/" title="playwright"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="playwright"/></a><div class="content"><a class="title" href="/blog/2024/04/26/python/13%E3%80%81playwright/" title="playwright">playwright</a><time datetime="2024-04-26T07:30:36.069Z" title="发表于 2024-04-26 15:30:36">2024-04-26</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By 侯玉东</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><div class="aplayer no-destroy" data-id="8873950678" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"> </div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener
  btf.removeGlobalFnEvent('pjax')
  btf.removeGlobalFnEvent('themeChange')

  document.getElementById('rightside').classList.remove('rightside-show')
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', e => {
  if (e.request.status === 404) {
    pjax.loadUrl('/blog/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>